﻿
 
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
	<head>
		
		<title>jb-aptech毕业设计项目</TITLE>
<meta name="renderer" content="ie-comp">
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
		<link href="../../css/style.css" rel="stylesheet" type="text/css">
		<script src="../../script/common.js"></script>
		<script src="../../script/validate.js"></script>
        <link rel="stylesheet" href="/css/bootstrap.min.css" type="text/css"></link>
        <script type="text/javascript" src="/js/jquery.min.js"></script>
        <script type="text/javascript" src="/js/bootstrap.min.js"></script>
        <script type="text/javascript" src="/js/vue.js"></script>
<script type="text/javascript"> 
	function allch(code){
		var temp = document.getElementById(code);
		var rs = document.getElementsByName("sysRight");
	//var rs=document.getElementsByTagName("sysRight");
		if(temp.checked){
			for(var i=0;i<rs.length;i++){
				if(rs[i].id.substring(0,3)==code){	
					rs[i].checked=true;
				}
			}			
		}else{
			for(var i=0;i<rs.length;i++){
				if(rs[i].id.substring(0,3)==code){
					rs[i].checked=false;
				}
			}
		}		
	}
	function selSup(code){
		var temps = document.getElementById(code);
		if(temps.checked){
			var sup = document.getElementById(code.substring(0,3));
			sup.checked=true;
		}else{
			var rs = sysRoleForm["sysRight"];
			var currRightId =code.substring(0,3);
			var flag = true;
			for(var i=0;i<rs.length;i++){
				if(rs[i].id!=currRightId &&rs[i].id.substring(0,3)==currRightId){
					if(rs[i].checked==true){
						flag=false;//其中有子节点被选中
					}
				}
			} 
			if(flag){
				document.getElementById(currRightId).checked=false;
			}
		}
	}
</script>
	</head>
  
  <body>
  <div class="page_title">
      权限管理 > 用户管理 > 系统角色管理 > 权限分配
  </div>
  <div id="might">
      <input type="hidden" name="method" value="doAssignRights">

      <table class="query_form_table">
          <tr>
              <th>角色名</th>
              <td>{{sysMight.role_name}}</td>
              <th>角色描述</th>
              <td>{{sysMight.role_desc}}</td>
              <th>状态</th>
              <td>{{sysMight.role_flag==1?'正常':'禁止'}}</td>
          </tr>
          <tr>
              <th>权限</th>
              <td colspan="5" align="center">
                  <input type="reset" value="取消" class="common_button">
                  <input type="button" value="保存" @click="save()" class="common_button">
              </td>
          </tr>
      </table>
      <br/>
      <table class="query_form_table" >

          <tr><td>
              &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;

              <input type="checkbox" v-model="allCode" @click="setValue()">

              <div v-for="m in mights" v-if="m.right_parent_code==0">


                  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                  <hr>
                  <div id="dd">
                  <div style="background-color:#CCCCCC;">
                      &nbsp;&nbsp;&nbsp;{{m.right_text}}
                      <input type="checkbox" checked="checked" v-model="m.mightFlag" @click="setSub(m)">
                  </div><br>

                  <span v-for="sub in mights" v-if="sub.right_parent_code==m.right_code">
					&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;

					  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{{sub.right_text}}
						<input type="checkbox"  checked="checked" v-model="sub.mightFlag" @change="setParent(m)">
                    </span>
                  </div>
              </div>
          </td>
          </tr>


      </table>
  </div>
    <script>
        var app=new Vue({
            el:"#might",
            data:{
                mights:[],
                sysMight:{
                    role_name:'',
                    role_desc:'',
                    role_flag:'',
                    role_id:''
                },
                roleid:'',
                flag:false,
                allCode:false
            },
            methods:{
                save(){
                    var arr=new Array();
                    var j=0;
                    $.each(this.mights,function(i){
                        if(this.mightFlag==1){
                            arr[j++]=this.right_code;
                        }
                    });
                    $.get("/delMightToRose/"+this.sysMight.role_id);
                    alert("保存成功！");
                        $.ajax({
                            url:"/saveMightToRose",
                            type:"post",
                            traditional:true,  //传数组要加这个属性
                            data:{"arr":arr,"roleid":this.roleid},
                            success:function (json) {
                                if(json.code==200){
                                    muli(this.roleid);
                                    return;
                                }else{
                                    alert("保存失败！");
                                }
                            }
                        });
                },
                setValue(){
                    app.flag = this.allCode ? false : true;
                    $.each(this.mights, function () {
                        this.mightFlag = app.flag;
                    });
                },
                setSub(right) {
                    $.each(this.mights, function () {
                        if (this.right_parent_code == right.right_code) {
                            this.mightFlag = right.mightFlag ? false : true;
                        }
                    });
                },
                setParent(right) {
                    right.mightFlag = false; //默认不选中父元素
                    $.each(this.mights, function () {
                        if (this.right_parent_code == right.right_code) {//找到子元素
                            if (this.mightFlag) {  //只要有一个元素选中了  父元素选中
                                right.mightFlag = true;
                            }
                        }
                    });
                }
            },
            created(){
                var r=sessionStorage.getItem("r");
                var ro=JSON.parse(r);
                this.sysMight=ro;
                this.roleid=ro.role_id;
                muli(this.roleid);
            }
        });
        function muli(id) {
            $.getJSON("/getMenuByRoleId2/"+id,function(json){
                app.mights=json.data.mights;
            });
        }
    </script>
  </body>
</html>
